import Request from 'luch-request'

// import encode from '../tools/encode.js'
import flyrise from "../tools/flyrise.js"

/**
 * 只负责登录，业务请求，参考attach.js
 * */

const request = new Request()
request.setConfig((config) => {
	config.header = {
		...config.header
	}
	console.log("-->>>config:", config)
	return config
})

request.interceptors.request.use((config) => {
	config.baseURL = flyrise.getBasePath() /* 根域名不同 */
	// #ifdef MP-WEIXIN
	let wechatId = flyrise.getWechatId()
	if (wechatId) {
		config.header = {
			...config.header
		}
	}
	// #endif
	return config
}, (config) => {
	return Promise.reject(config)
})

/**刷新token*/
export const refreshToken = (refreshToken) => {
	return request.post(`/auth-api/oauth/token`, {
		refresh_token: refreshToken,
		grant_type: 'refresh_token',
		scope: 'server',
		client_id: 'mobile',
		client_secret: '123456',
	}, {
		header: {
			"Content-Type": "application/x-www-form-urlencoded"
		}
	})
}
